(function Init(module, exports) {
    exports.bg=new background();
    function _classCallCheck(e, t) {
        if (!(e instanceof t))
            throw new TypeError("Cannot call a class as a function")
    }
    function _defineProperties(e, t) {
        for (var n = 0; n < t.length; n++) {
            var a = t[n];
            a.enumerable = a.enumerable || !1,
                a.configurable = !0,
            "value" in a && (a.writable = !0),
                Object.defineProperty(e, a.key, a)
        }
    }
    function _createClass(e, t, n) {
        return t && _defineProperties(e.prototype, t),
        n && _defineProperties(e, n),
            e
    }
    var Utils = function() {
        function e() {
            _classCallCheck(this, e)
        }
        return _createClass(e, null, [{
            key: "insert_local_style",
            value: function(e) {
                return new Promise(function(t) {
                        chrome.tabs.insertCSS(null, {
                            file: e
                        }, function(e) {
                            t("ok")
                        })
                    }
                )
            }
        }, {
            key: "insert_code_style",
            value: function(e) {
                return new Promise(function(t) {
                        chrome.tabs.insertCSS(null, {
                            code: e
                        }, function(e) {
                            t("ok")
                        })
                    }
                )
            }
        }, {
            key: "insert_cdn_style",
            value: function(e) {
                return new Promise(function(t) {
                        jQuery.ajax({
                            url: e,
                            dataType: "text",
                            success: function(e) {
                                chrome.tabs.insertCSS(null, {
                                    code: e
                                }, function(e) {
                                    t("ok")
                                })
                            }
                        })
                    }
                )
            }
        }, {
            key: "inject_local_script",
            value: function(e) {
                return new Promise(function(t) {
                        chrome.tabs.executeScript(null, {
                            file: e
                        }, function(e) {
                            t("ok")
                        })
                    }
                )
            }
        }, {
            key: "inject_code_script",
            value: function(e) {
                return new Promise(function(t) {
                        chrome.tabs.executeScript(null, {
                            code: e
                        }, function(e) {
                            t("ok")
                        })
                    }
                )
            }
        }, {
            key: "inject_cdn_script",
            value: function(e) {
                return new Promise(function(t) {
                        jQuery.ajax({
                            url: e,
                            dataType: "text",
                            success: function(e) {
                                chrome.tabs.executeScript(null, {
                                    code: e
                                }, function(e) {
                                    t("ok")
                                })
                            }
                        })
                    }
                )
            }
        }, {
            key: "getUrlTextData",
            value: function(e) {
                return new Promise(function(t) {
                        jQuery.ajax({
                            url: e,
                            dataType: "text",
                            success: function(e) {
                                t(e)
                            }
                        })
                    }
                )
            }
        }, {
            key: "getData",
            value: function(e, t) {
                return new Promise(function(n) {
                        var a = {
                            url: e,
                            type: "GET",
                            dataType: "json",
                            success: function(e) {
                                n(e)
                            }
                        }
                            , r = jQuery.extend(!0, a, t);
                        jQuery.ajax(r)
                    }
                )
            }
        }, {
            key: "postData",
            value: function(e, t) {
                return new Promise(function(n) {
                        var a = {
                            url: e,
                            type: "POST",
                            dataType: "json",
                            success: function(e) {
                                n(e)
                            }
                        }
                            , r = jQuery.extend(!0, a, t);
                        jQuery.ajax(r)
                    }
                )
            }
        }, {
            key: "ajaxData",
            value: function(e) {
                return new Promise(function(t) {
                        var n = e || {};
                        n.error = function() {
                            t(null)
                        }
                            ,
                            n.success = function(e) {
                                t(e)
                            }
                            ,
                            jQuery.ajax(n)
                    }
                )
            }
        }]),
            e
    }();
    bg.on(function(request, sender, sendResponse) {
        var type = request.type
            , data = request.data;
        switch (type) {
            case "open_url":
                chrome.tabs.create({
                    url: data[0]
                });
                sendResponse();
                break;
            case "ajax_data":
                Utils.ajaxData(data[0]).then(function(e) {
                    sendResponse({
                        data: e
                    })
                });
                break;
            case "get_text_data":
                Utils.getUrlTextData(data[0]).then(function(e) {
                    sendResponse({
                        data: e
                    })
                });
                break;
            case "get_data":
                var _obj = data[1] ? data[1] : {};
                Utils.getData(data[0], _obj).then(function(e) {
                    sendResponse({
                        data: e
                    })
                });
                break;
            case "post_data":
                var _obj = data[1] ? data[1] : {};
                Utils.postData(data[0], _obj).then(function(e) {
                    sendResponse({
                        data: e
                    })
                });
                break;
            case "run_in_background":
                new Promise(function(resolve) {
                        eval(data[0])
                    }
                ).then(function(e) {
                    sendResponse({
                        data: e
                    })
                });
                break;
            case "all_in_background":
                eval(data[0]);
                break;
            case "insert_local_style":
            case "insert_code_style":
            case "insert_cdn_style":
            case "inject_local_script":
            case "inject_code_script":
            case "inject_cdn_script":
                if ("function" == typeof Utils[type] && data.length) {
                    for (var queue = [], i = 0; i < data.length; i++)
                        queue.push(Utils[type](data[i]));
                    Promise.all(queue).then(function(e) {
                        sendResponse({
                            code: e.length
                        })
                    })
                }
        }
        return !0
    })
})(document,window);